package com.shopowner.dao.impl;


import com.shopowner.entity.Activitytype;
import com.shopowner.page.PageInfo;
import com.shopowner.utils.GenNumTools;
import com.shopowner.dao.ActivitytypeDao;
import com.shopowner.mapper.ActivitytypeMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("activitytypeDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名
public class ActivitytypeDaoImpl implements ActivitytypeDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private ActivitytypeMapper activitytypeMapper;
    public List<Activitytype>  getAllActivitytypes() throws Exception{
        return activitytypeMapper.selectByExample(null);
    }

    @Override
    public Integer deleteActivitytypeByAtno(String atno)  throws Exception{
        return activitytypeMapper.deleteByPrimaryKey(atno);
    }

    @Override
    public Integer updateActivitytypeByAtno(Activitytype activitytype)  throws Exception{
        return activitytypeMapper.updateByPrimaryKey(activitytype);
    }

    @Override
    public Integer addActivitytype(Activitytype activitytype)  throws Exception{
        activitytype.setAtno(initId());
        return activitytypeMapper.insertSelective(activitytype);
    }
    public String initId(){
        String maxAtno = activitytypeMapper.getMaxAtno();
        return GenNumTools.initId("s",4,maxAtno);
    }
    @Override
    public List<Activitytype> getActivitytypeByPage(PageInfo pageInfo )  throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount = (int)activitytypeMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return activitytypeMapper.getActivitytypeByPage(map);
    }


}
